package com.muyu.system.service.impl;


import com.muyu.common.core.domain.Result;
import com.muyu.common.core.utils.DateUtils;
import com.muyu.system.domain.DanmoSecurityLogs;
import com.muyu.system.mapper.DanmoSecurityLogsMapper;
import com.muyu.system.service.IDanmoSecurityLogsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 安全日志
Service业务层处理
 * 
 * @author yangle
 * @date 2025-03-08
 */
@Service
public class DanmoSecurityLogsServiceImpl implements IDanmoSecurityLogsService
{
    @Autowired
    private DanmoSecurityLogsMapper danmoSecurityLogsMapper;

    /**
     * 查询安全日志

     * 
     * @param id 安全日志
主键
     * @return 安全日志

     */
    @Override
    public DanmoSecurityLogs selectDanmoSecurityLogsById(Long id)
    {
        return danmoSecurityLogsMapper.selectDanmoSecurityLogsById(id);
    }

    /**
     * 查询安全日志
列表
     * 
     * @param danmoSecurityLogs 安全日志

     * @return 安全日志

     */
    @Override
    public List<DanmoSecurityLogs> selectDanmoSecurityLogsList(DanmoSecurityLogs danmoSecurityLogs)
    {
        return danmoSecurityLogsMapper.selectDanmoSecurityLogsList(danmoSecurityLogs);
    }

    /**
     * 新增安全日志

     * 
     * @param danmoSecurityLogs 安全日志

     * @return 结果
     */
    @Override
    public Result insertDanmoSecurityLogs(DanmoSecurityLogs danmoSecurityLogs)
    {
        danmoSecurityLogs.setCreateTime(DateUtils.getNowDate());

//        LoginUser loginUser = SecurityUtils.getLoginUser();
//        if (loginUser == null){
//            return Result.notLoggedIn("请登录");
//        }
//        danmoSecurityLogs.setUserId(loginUser.getUserid());
//        //获取ip地址
//        danmoSecurityLogs.setIp(loginUser.getIpaddr());
//        danmoSecurityLogs.setCreateBy(loginUser.getUsername());
//        danmoSecurityLogs.setAction(loginUser.getUsername()+" "+danmoSecurityLogs.getAction());

        danmoSecurityLogsMapper.insertDanmoSecurityLogs(danmoSecurityLogs);
        return Result.success(danmoSecurityLogs,"新增成功");
    }

    /**
     * 修改安全日志

     * 
     * @param danmoSecurityLogs 安全日志

     * @return 结果
     */
    @Override
    public Result updateDanmoSecurityLogs(DanmoSecurityLogs danmoSecurityLogs)
    {
        danmoSecurityLogs.setUpdateTime(DateUtils.getNowDate());
        danmoSecurityLogsMapper.updateDanmoSecurityLogs(danmoSecurityLogs);
        return Result.success(danmoSecurityLogs,"修改成功");
    }

    /**
     * 批量删除安全日志
     *
     * @param ids 需要删除的安全日志
     * @return 结果
     */
    @Override
    public Result deleteDanmoSecurityLogsByIds(Long[] ids)
    {
        danmoSecurityLogsMapper.deleteDanmoSecurityLogsByIds(ids);
        return Result.success(ids,"删除成功");
    }

    /**
     * 删除安全日志
     * 
     * @param id 安全日志
     * @return 结果
     */
    @Override
    public Result deleteDanmoSecurityLogsById(Long id)
    {
        danmoSecurityLogsMapper.deleteDanmoSecurityLogsById(id);
        return Result.success(id,"删除成功");
    }
}
